<script type="text/javascript">//<![CDATA[
var HideAdvance = 0;
function onWsplcAdvance( )
{
	var objAdv = document.getElementById("wsplc-advance");
	if(HideAdvance)
	{
		HideAdvance = 0;
		objAdv.value = "Hide Advanced Settings";
	}
	else
	{
		HideAdvance = 1;
		objAdv.value = "Show Advanced Settings";
	}

	for (var i=0; i<objAdv.form.length; i++ )
	{
		var objElm = objAdv.form.elements[i];
		if (objElm.className == "cbi-section"
			&& objElm.id != "cbi-wsplcd-config"
			&& objElm.id != "cbi-apply-wsplcd")
		{
			if (HideAdvance)
				objElm.style.display = "none";
			else
				objElm.style.display = "block";
		}
	}
}

function wsplcSetDisabled(option, disabled)
{
	var id = "cbid.wsplcd.config." + option;
	var obj = document.getElementById(id);
	if (!obj)
		return;

	if (obj.type == "text")
		obj.readOnly = disabled;
	else
		obj.disabled = disabled;
}

function onConfigChange( )
{
	var objHyfisec = document.getElementById("cbid.wsplcd.config.HyFiSecurity");
	var objMode = document.getElementById("cbid.wsplcd.config.RunMode");
	var objBandSel = document.getElementById("cbid.wsplcd.config.BandSel");

	if (objHyfisec.checked == false)
	{
		wsplcSetDisabled("RunMode", true);
	}
	else
	{
		wsplcSetDisabled("RunMode", false);
	}

	if (objHyfisec.value == 0 || objMode.value == "ENROLLEE")
	{
		wsplcSetDisabled("NetworkKey1905", true);
		wsplcSetDisabled("UCPKSalt", true);
        }
	else
	{
		wsplcSetDisabled("NetworkKey1905", false);
		wsplcSetDisabled("UCPKSalt", false);
	}

	if (objMode.value == "REGISTRAR" ||
		objMode.value == "NONE")
	{
		wsplcSetDisabled("ConfigSta", true);
		wsplcSetDisabled("SearchTimeout", true);
		wsplcSetDisabled("SSIDSuffix", true);
		wsplcSetDisabled("BandSel", true);
		wsplcSetDisabled("BandChoice", true);
		wsplcSetDisabled("RMCollectTimeout", true);
		wsplcSetDisabled("RXMode", true);
		if (objMode.value == "NONE")
		{
			wsplcSetDisabled("WPSSessionTimeout", true);
			wsplcSetDisabled("WPSRetransmitTimeout", true);
			wsplcSetDisabled("WPSPerMessageTimeout", true);
		}
		else
		{
			wsplcSetDisabled("WPSSessionTimeout", false);
			wsplcSetDisabled("WPSRetransmitTimeout", false);
			wsplcSetDisabled("WPSPerMessageTimeout", false);
		}
		wsplcSetDisabled("WPSMethod", false);
		wsplcSetDisabled("TXMode", false);
	}
	else
	{
		wsplcSetDisabled("ConfigSta", false);
		wsplcSetDisabled("SearchTimeout", false);
		wsplcSetDisabled("SSIDSuffix", false);
		wsplcSetDisabled("BandSel", false);

		if (objBandSel && objBandSel.value == 1)
		{
			wsplcSetDisabled("BandChoice", false);
			wsplcSetDisabled("RMCollectTimeout", false);
		}
		else
		{
			wsplcSetDisabled("BandChoice", true);
			wsplcSetDisabled("RMCollectTimeout", true);
		}

		wsplcSetDisabled("RXMode", false);
		wsplcSetDisabled("WPSSessionTimeout", false);
		wsplcSetDisabled("WPSRetransmitTimeout", false);
		wsplcSetDisabled("WPSPerMessageTimeout", false);

		wsplcSetDisabled("WPSMethod", true);
		wsplcSetDisabled("TXMode", true);
	}
}


function onModeChange( )
{
	var objMode = document.getElementById("cbid.wsplcd.config.RunMode");
	var objPbap = document.getElementById("cbid.wsplcd.config.DesignatedPBAP");
	if (objMode.value == "REGISTRAR")
		objPbap.value = 1;
	else
		objPbap.value = 0;

	onConfigChange();
}

function onWsplcLoad()
{
	var objHyfisec = document.getElementById("cbid.wsplcd.config.HyFiSecurity");
	objHyfisec.onchange = onConfigChange;

	var objMode = document.getElementById("cbid.wsplcd.config.RunMode");
	objMode.onchange = onModeChange;

	var objBandSel = document.getElementById("cbid.wsplcd.config.BandSel");
	objBandSel.onchange = onConfigChange;

        var objAdv = document.getElementById("wsplc-advance");
	if (objAdv)
	{
		objAdv.onclick = onWsplcAdvance;
	}

	wsplcSetDisabled("WPAPSK", true);
	wsplcSetDisabled("1901NMK", true);
	onConfigChange();
	onWsplcAdvance();
}

if (document.all)
	window.attachEvent('onload', onWsplcLoad);
else
	window.addEventListener('load', onWsplcLoad, false);
//]]></script>

